package org.lw.springbootlw.common.mapper.auth;


import org.apache.ibatis.annotations.*;
import org.lw.springbootlw.common.model.User;
import java.util.List;
import java.util.Optional;

@Mapper
public interface UserMapper {

    @Select("SELECT * FROM Users u WHERE u.username = #{username}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "password", column = "password"),
            @Result(
                    property = "roles", column = "id",
                    many = @Many(select = "org.lw.springbootlw.common.mapper.auth.RoleMapper.findRolesByUserId"))
    })
    Optional<User> findUserWithRolesByUsername(@Param("username") String username);

}

